home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 04 / viewport.h < prev    next >
C/C++ Source or Header  |  1991-05-03  |  5KB  |  101 lines

  1. /*  viewport.h- viewport Definition and Macros */
  2. #ifndef __VIEWPORT_H
  3. #define __VIEWPORT_H
  4.  
  5. #include <alloc.h>              /* needed for farmalloc prototype */
  6.  
  7. #ifdef NEAR_HEAP
  8. #       define VMALLOC   malloc /* Allocate memory for buffer.          */
  9. #       define VFREE     free   /* Free memory used for buffer.         */
  10.         typedef char     *cptr; /* pointer to a character buffer        */
  11.         typedef int      *iptr; /* pointer to an int buffer             */
  12. #else
  13. #       define VMALLOC    farmalloc
  14. #       define VFREE      farfree
  15.         typedef char far* cptr;
  16.         typedef int  far* iptr;
  17. #endif
  18.  
  19. #define VMAXCOLS        80      /* Max. columns in a viewport           */
  20. #define VMAXLINES       50      /* Max. lines (rows) in a viewport      */
  21. #define VMAGIC          0xcdef  /* Magic number used to recognize a     */
  22.                                 /* valid viewport.                      */
  23. #define VINIT_CHAR      ' '     /* clearok and v_scroll_region init.    */
  24.                                 /* viewport w/ this character           */
  25. typedef struct viewport
  26. {
  27.     unsigned magic;        /* Magic number---identifies a valid viewport */
  28.  
  29.     unsigned inactive: 1 ; /* viewport is deactivated but still open.        */
  30.     unsigned closed  : 1 ; /* viewport is closed and deactivated.            */
  31.     unsigned clearok : 1 ; /* Clear (fill with blanks) viewport on 1st open. */
  32.     unsigned saveok  : 1 ; /* Save area under viewport before displaying it  */
  33.  
  34.     unsigned char nrows  ; /* number of rows in viewport                     */
  35.     unsigned char ncols  ; /* number of columns in viewport                  */
  36.  
  37.     unsigned char row;  /* absolute coordinate of upper-left corner */
  38.     unsigned char col;
  39.  
  40.     unsigned char cur_row;       /* cursor position     */
  41.     unsigned char cur_col;
  42.  
  43.     unsigned char fcolor;        /* foreground color    */
  44.     unsigned char bcolor;        /* background color    */
  45.  
  46.     iptr savebuf;     /* underlying text when window was first opened */
  47.     iptr old_image;   /* old image when window closed or deactivated  */
  48. }
  49. viewport;
  50.  /*----------------------------------------------------------------------*/
  51. #define v_valid(      v       ) ((v)->magic == VMAGIC)
  52. #define v_foreground( v, color) ((v)->fcolor =  (color) )
  53. #define v_background( v, color) ((v)->bcolor =  (color) )
  54. #define v_saveok(     v, on   ) ((v)->saveok =  (on)!=0 )
  55. #define v_clearok(    v, on   ) ((v)->clearok=  (on)!=0 )
  56. #define v_getposn( rp, cp     ) ((*(rp)=(v)->row),   (*(cp)=(v)->col) )
  57. #define v_row(     v ) (v_valid(v)? ( (v)->cur_row                ):-1)
  58. #define v_col(     v ) (v_valid(v)? ( (v)->cur_col                ):-1)
  59. #define v_nrows(   v ) (v_valid(v)? ( (v)->nrows                  ): 0)
  60. #define v_ncols(   v ) (v_valid(v)? ( (v)->ncols                  ): 0)
  61. #define v_ateol(   v ) (v_valid(v)? ( (v)->cur_col== (v)->ncols-1 ): 0)
  62. #define v_atbol(   v ) (v_valid(v)? ( (v)->cur_col== 0            ): 0)
  63. #define v_ateob(   v ) (v_valid(v)? ( (v)->cur_row== (v)->nrows-1 ): 0)
  64. #define v_advance( v ) v_gotorc( (v), (v)->cur_row, (v)->cur_col + 1  )
  65. #define v_backup(  v ) v_gotorc( (v), (v)->cur_row, (v)->cur_col - 1  )
  66. #define v_cr(      v ) v_gotorc( (v), (v)->cur_row    , 0             )
  67. #define v_up(      v ) v_gotorc( (v), (v)->cur_row - 1, (v)->cur_col  )
  68. #define v_down(    v ) v_gotorc( (v), (v)->cur_row + 1, (v)->cur_col  )
  69.  
  70. #define v_scroll(v,u,l) v_scroll_region(v,u,l,0,0,VMAXCOLS,VMAXLINES)
  71. #define v_move_rel(v, dr, dc) v_move((v), (v)->row-(dr), (v)->col-(dc))
  72.  
  73. /*----------------------------------------------------------------------*/
  74. int  v_startup    ( int mode    );
  75. void v_shutdown   ( void        );
  76. int  v_construct  ( viewport *v );
  77. int  v_destroy    ( viewport *v );
  78. int  v_open       ( viewport *v );
  79. int  v_close      ( viewport *v );
  80. int  v_deactivate ( viewport *v, int hide );
  81. int  v_size       ( viewport *v, unsigned nrows, unsigned ncols );
  82. int  v_move       ( viewport *v, unsigned row,   unsigned col   );
  83. int  v_gotorc     ( viewport *v, unsigned row,   unsigned col   );
  84. int  v_putc       ( viewport *v, int c, int move_cur );
  85. int  v_puts       ( viewport *v, char *s );
  86. int  v_getc       ( viewport *v );
  87. int  v_gets       ( viewport *v, int n,  char *s  );
  88. int  v_scroll_region( viewport *v, int up, int to_left, int left, int top,
  89.                                                         int right, int bottom );
  90. int  v_clear        ( viewport *v );
  91. int  v_cleartoeol   ( viewport *v );
  92.  
  93. /* Workhorse functions, not intended to be user callable
  94. */
  95.  
  96. void _v_save_scr    (iptr image, int row, int col, int nrows, int ncols);
  97. void _v_restore_scr (iptr image, int row, int col, int nrows, int ncols);
  98. void _v_fill_scr    (int c_att,  int row, int col, int nrows, int ncols);
  99.  
  100. #endif /* #ifdef __VIEWPORT_H */
  101.